package com.ccc.javacv.controller;

import com.ccc.javacv.service.ConvertService;
import com.ccc.javacv.pojo.VideoInfo;
import com.ccc.javacv.response.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 任务
 *
 * @author superC
 * @version 1.0.0
 * @date 2022/12/6
 */

@RestController
@RequestMapping("/task")
public class TaskController {

    @Autowired
    private ConvertService convertService;

    /**
     * get list
     */
    @GetMapping("livem")
    public ResponseResult list() {
        return ResponseResult.success("获取数据成功", convertService.listTasks());
    }

    /**
     * add stable
     */
    @PostMapping("livem")
    public ResponseResult add(@RequestBody VideoInfo videoInfo) {
        convertService.addStableTask(videoInfo);
        return ResponseResult.success();
    }

    /**
     * delete stable
     */
    @DeleteMapping("livem/{taskId}")
    public Object delete(@PathVariable String taskId) {
        convertService.deleteStableTask(taskId);
        return ResponseResult.success();
    }

    /**
     * restart
     */
    @PostMapping("livem/{taskId}/restart")
    public ResponseResult restart(@PathVariable String taskId) {
        convertService.restartTask(taskId);
        return ResponseResult.success();
    }

}